﻿<?php
session_start();

if (!isset($_SESSION['kid'])) {
  
    include("startseite.php");
    exit();
}
?>

<!DOCTYPE html>
<html lang="de">
  <head>
    <meta charset="utf-8 ">
   
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>öffnentisch</title>
   	<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
	<link href="bootstrap/css/style.css" rel="stylesheet">
	<link href="bearbeitung.css" rel="stylesheet">
    <script src="js/bon.js"></script>
    <script src="js/jquery-1.11.1.min.js"></script>
    <script src="bootstrap/js/bootstrap.min.js"></script>
    
    
    <script type="text/javascript">
		
		jQuery( document ).ready(function(){
			var z=""; //zahl
			var table_row_index;
			var menge =[];
			var gericht = [];
			var gerichtid=[];
			var preis = [];
			var sum=0;
			$( "#w1" ).show();
			$( "#so1" ).hide();
			$( "#ape1" ).hide();			
			$( "#hot1" ).hide();	
			$( "#bw1" ).hide();			
			$( "#ma1" ).hide();			
			$( "#des1" ).hide();			
		
			$("#scrollarea").click(function(){
				$("td").css( "color", "red" );
				$('td').click(function(){
					$(this).css( "color", "red" );
					table_row_index = $(this).parent().index();
					 menge.splice(table_row_index,1);
					 gericht.splice(table_row_index,1);
					 $("#scrollarea").html(showInScroll(menge,gericht,preis)).show();
				});
			});
						
			//zahl eingeben
			$("z").click(function(){
				if ($(this).text()=="clear"){
					z="";
					$("#scrollarea").text(z).show(); 		
				}else{
					z=z+getzahl($(this).text());
					$("#scrollarea").text(z).show();
				}
			});
					
			
			$( "w" ).click( function() {
				var preiseinzel= $(this).prop('title');
				var gid = parseInt($(this).prop('id'));
				
				if (z==""){
					menge.push(1);
					gericht.push($(this).text());
					gerichtid.push(gid);
					sum = sum + parseFloat(preiseinzel);
					preis.push(parseFloat(preiseinzel).toFixed(2));
					$("#scrollarea").html(showInScroll(menge,gericht,preis));
				}
				else if (z==0){
					z="";
					$("#scrollarea").html(showInScroll(menge,gericht,preis));
				}
				else{
					var preismal=parseInt(z) * parseFloat(preiseinzel).toFixed(2);
					menge.push(parseInt(z));
					gericht.push($(this).text());
					gerichtid.push(gid);
					sum += preismal;
					preis.push(preismal);
					$("#scrollarea").html(showInScroll(menge,gericht,preis));
					z="";
				}
			});
			
			$( "so" ).click( function() {
				$("#scrollarea").text($(this).text()).show();
			});	

			$( "ape" ).click( function() {
				$("#scrollarea").text($(this).text()).show();
			});
			
			
			// gericht button wechseln
			$( "a" ).click( function() {
				if($(this).text() == "BONSENDEN"){ // if Button OK is clicked
					var tnr = <?php echo  $_GET['t_nr'];?>;
					var gast =<?php echo $_GET['gz'];?>;				
					$.post('mealinput.php',	{tnr: tnr, gast : gast, gid: gerichtid, sm: sum, mge: menge,prs:preis})//,function(){
						//document.location= "bearbeitung.php";
						//document.location= "mealinput.php";})
					.done(function(){
						document.location= "bearbeitung.php";

					})
				}else{
					choosemeal($(this).text());
				}
			});
							
		});
	
	</script>
	
  </head>
	<body>
	<br>

	<div class= "container" style ="background: #123456;">	
		<div class= "jumbotron" style = "background-color: #341256; text-align: center;">
			<p style = "color: white; font-size: 30px;">  Nam Bộ Restaurant</p>
		</div>
		<div class= "row">
			
			<div class= "btn-group  btn-group-justified">
				<a class="btn btn-danger btn-sm btn-block" role="button" style ="font-size: 14px;"><b>Tischnr: <?php echo $_GET['t_nr'];?></b></a>
			
		
				<a class="btn btn-danger btn-sm btn-block" role="button" style ="font-size: 14px;"><b>Zeit: <?php date_default_timezone_set('Europe/Berlin'); echo date("H:i");?></b></a>
			
			
				<a class="btn btn-danger btn-sm btn-block" role="button" style ="font-size: 14px;"><b>Kellner: <?php echo $_SESSION['kid'];?></b></a>
			
			
				<a class="btn btn-danger btn-sm btn-block" role="button" style ="font-size: 14px;"><b>Gast: <?php echo $_GET['gz'];?></b></a>
			
			</div>
		</div>
		<br>
	</div>
	<br>
	<div class= "container" style ="background: #123456;">
		<div class= "row">
			<div class="col-xs-6 col-md-4">
				<br>
				<div  id ="scrollarea"  style ="font-size: 15px;  width:350px; height:505px; overflow: auto;background:white;">
				
				</div>
				
			</div>
			
			<div class=" col-xs-6 col-md-1" >
				<br>
				<z class="btn btn-warning btn-sm btn-block" style ="font-size: 15px;color:#5c0507;">clear</z>				
				<z class="btn btn-warning btn-sm btn-block" style ="font-size: 15px;color:#5c0507;">0</z>
				<z class="btn btn-warning btn-sm btn-block" style ="font-size: 15px; color:#5c0507">1</z>
				<z  class="btn btn-warning btn-sm btn-block" style ="font-size: 15px;color:#5c0507">2</z>
				<z class="btn btn-warning btn-sm btn-block" style ="font-size: 15px;color:#5c0507">3</z>
				<z class="btn btn-warning btn-sm btn-block" style ="font-size: 15px;color:#5c0507">4</z>
				<z class="btn btn-warning btn-sm btn-block" style ="font-size: 15px;color:#5c0507">5</z>
				<z class="btn btn-warning btn-sm btn-block" style ="font-size: 15px;color:#5c0507">6</z>
				<z class="btn btn-warning btn-sm btn-block" style ="font-size: 15px;color:#5c0507">7</z>
				<z class="btn btn-warning btn-sm btn-block" style ="font-size: 15px;color:#5c0507">8</z>
				<z class="btn btn-warning btn-sm btn-block" style ="font-size: 15px;color:#5c0507">9</z>
				<z class="btn btn-warning btn-sm btn-block" style ="font-size: 15px;color:#5c0507">x</z>
				<br>
				
			</div>
			<div class=" col-xs-6 col-md-2">
				<br>
				<a class="btn btn-success btn-lg btn-block" style ="font-size: 15px;"><b>Wasser/Säfte</b><br></a>
				<a class="btn btn-success btn-lg btn-block" style ="font-size: 15px;"><b>Softdrink</b><br></a>
				<a class="btn btn-success btn-lg btn-block" style ="font-size: 15px;"><b>Hotdrink</b><br></a>
				<a class="btn btn-success btn-lg btn-block" style ="font-size: 15px;"><b>Bier/Wein</b><br></a>
				<a class="btn btn-success btn-lg btn-block" style ="font-size: 15px;"><b>Longdrink</b><br></a>
				<a class="btn btn-danger btn-lg btn-block" style ="font-size: 15px;"><b>Vorspeise</b><br></a>
				<a class="btn btn-danger btn-lg btn-block" style ="font-size: 15px;"><b>Hauptspeise</b><br></a>
				<a class="btn btn-danger btn-lg btn-block"  style ="font-size: 15px;"><b>Mittag</b><br></a>
				<a class="btn btn-danger btn-lg btn-block"  style ="font-size: 15px;"><b>Nachspeise</b><br></a>
				<a class="btn btn-info btn-lg btn-block"  style ="font-size: 15px;"><b>Als 1.Gang</b><br></a>
				<a class="btn btn-info btn-lg btn-block"  style ="font-size: 15px;"><b>Als 2.Gang</b><br></a>
				<br>
			</div>
			<div class="col-xs-6 col-md-5" style = "background: #341256; overflow:auto;">
				<div id ="fenster2"  style = "background: #341256; text-align: center; height:525px;">
				
				<?php
					require_once("db/connectDB.php");	
					callMeal("w1",115,124);
					callMeal("so1",125,134);
					callMeal("hot1",135,140);
					callMeal("bw1",141,150);
					callMeal("ape1",1,18);
					callMeal("ma1",19,35);
					callMeal("des1",36,41);	
				?>
				</div>
				
			</div>
			
		</div>
		
	</div>
	</div>
	<div class= "container" style = "background: #341256;">
		<div class="row">

				<div class=" col-md-12">
					
					
					<a class="btn btn-warning btn-lg tbn-block" style="font-size:25px;">BON<br>SENDEN<br><br></a>
							
					<a class="btn btn-default btn-lg tbn-block" style="font-size:25px;">ZW.<br>Rechnung<br><br></a>
					
					<a class="btn btn-primary btn-lg tbn-block" style="font-size:25px;"><br>ZAHLUNG<br><br></a>
					
					<a class="btn btn-info btn-lg tbn-block" style="font-size:25px;"><br>Funktion<br><br></a>
					
					<a class="btn btn-danger btn-lg tbn-block" style="font-size:25px;"><br>STORNO<br><br></a>
					
					<a  class="btn btn-danger btn-lg tbn-block" style="font-size:25px;"><br>ABBRECHEN<br><br></a>
				</div>
		</div> 
	</div> 
	
	</body>
</html>

	
<?php

	function callMeal($div, $id1, $id2){
		
		$j=3;
		$i=0;
		mysql_query("SET NAMES 'utf8'");
		$result =mysql_query("select * from gericht where id >=$id1 and id<=$id2");
		echo "<div id =$div>";
		while ($row= mysql_fetch_array($result)){
			if($i==0 ||$i==$j){
				if($i==$j) {
					$j=3+$j;
				}
				echo "<div  class= 'row'>";
				echo "<div class= 'col-xs-6 col-md-4'>";
				echo "<w id =". $row['id']." type= 'button' class='btn btn-success btn-lg btn-block' style ='font-size: 15px;'>".$row['named']." title = ".$row['preis']."</w>";
				echo "</div>";
				$i++;
			}
			else{
				echo "<div  class= 'col-xs-6 col-md-4'>";
				echo "<w id =". $row['preis']." type= 'button' class='btn btn-success btn-lg btn-block' style ='font-size: 15px;'>".$row['named']."</w>";
				echo "</div>";
				if($i==($j-1)){
					echo "</div>";
					
					echo "<br>";
				}
				$i++;
			} 
		}
		$k= $i-1;
		$l= $j-3;
		//check 
		if($k===$l) {
			echo "</div>"; 
		}
		echo "</div>";
		mysql_free_result($result);	
	}
?>	